{include file="public/header"/}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>日志列表</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <!--搜索框开始-->
            <div class="row">
                <div class="col-sm-12">
                    <div  class="col-sm-2">
                        <div class="input-group" >
                            <button  class="btn btn-outline btn-danger" href="javascript:;" data-toggle="dropdown">
                                <i class="fa fa-wrench"></i> 批量操作 <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="javascript:;" class="layuiBtn" id="empty" data-type="reload"><i class="fa fa-retweet"></i> 重置搜索框 </a></li>
                                <li><a href="javascript:;" class="layuiBtn" data-type="getCheckData"><i class="fa fa-trash-o"></i> 批量删除 </a></li>
                            </ul>
                        </div>
                    </div>
                    <form id="layuiForm">
                        <div class="col-sm-4">
                            <div class="input-group" >
                                <input type="text"  name="start" onclick="laydate({istime: true,format: 'YYYY-MM-DD hh:mm:ss'})" class="form-control layer-date search" placeholder="开始日期"/>
                                <span class="input-group-addon">到</span>
                                <input type="text"  name="end" onclick="laydate({istime: true,format: 'YYYY-MM-DD hh:mm:ss'})"  class="form-control layer-date search" placeholder="结束日期"/>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="input-group">
                                 <select class="form-control m-b chosen-select search" name="key" >
                                    <option value="">选择管理员</option>
                                    {volist name="search_user" id="v"}
                                        <option value="{$key}" {if condition="$val eq $key"}selected{/if}>{$v}</option>
                                    {/volist}
                                </select>
                                <span class="input-group-btn">
                                    <a  class="btn btn-primary layuiBtn" data-type="reload"><i class="fa fa-search"></i> 搜索</a>
                                </span>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <!--搜索框结束-->
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Panel Other -->
{include file="public/footer" /}
<script>
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Log/operate_log")}'
            , page: true
            , even: false //开启隔行背景
            , size: 'lg' //小尺寸的表格
            // ,width:100
            , cellMinWidth: 80
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , text: {
                none: '暂无数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left',}
                , {field: 'log_id', width: 80, title: 'ID', sort: true, align: 'center'}
                , {field: 'admin_id', width: 80, title: '用户ID', sort: true, align: 'center'}
                , {field: 'admin_name', width: '', title: '操作用户', align: 'center', templet: '#imgTpl'}
                , {field: 'description', width: '', title: '描述', align: 'center', templet: '#titleTpl'}
                , {field: 'ip', width: '', title: '操作IP', align: 'center'}
                , {field: 'ipaddr', width: '', title: '地址', align: 'center'}
                , {field: 'add_time', width: '', title: '操作时间', sort: true, align: 'center'}
                , {field: 'status',fixed: 'right', width: 100, title: '状态', sort: true,align: 'center', templet: '#staBar'}
                , {fixed: 'right', width: 100, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            //配置状态
            wk.status(this.value,'{:url("status_config")}');
        });
        //搜索表格重载
        var $ = layui.$, active = {
            reload: function () {
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where:$('#layuiForm').parseForm()
                });
            }
            ,getCheckData: function(){
                //批量删除
                wk.batchDel(getIds(),"{:url('batchDelLog')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['id'])
            });
            return ids;
        }
    });
</script>
<!--状态模板-->
<script type="text/html" id="staBar">
    {{# if(d.status==1){ }}
        <span class="label label-info">操作成功</span>
    {{# }else{ }}
        <span class="label label-danger">操作失败</span>
    {{# } }}
</script>
<!--操作模板-->
<script type="text/html" id="opeBar">
    <a href="javascript:;" onclick="del_log({{d.log_id}})" class="btn btn-danger btn-outline btn-xs">
        <i class="fa fa-trash-o"></i> 删除</a>
</script>
<script type="text/javascript">
    //删除日志
    function del_log(log_id){
        wk.confirm(log_id,"{:url('del_log')}");
    }
</script>
</body>
</html>